﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.ComponentModel;
using System.Data;
//using System.Data.SqlClient;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Security.AccessControl;
using System.Text;
using System.Threading;
using System.Xml;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;

namespace UpdateSPFolderTitle
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite objSPSite = new SPSite("http://aaa/Sites/bb"))
            {
                using (SPWeb objSPWeb = objSPSite.OpenWeb("", true))
                {
                    objSPWeb.AllowUnsafeUpdates = true;
                    SPListCollection objSPListCollection = objSPWeb.Lists;
                    foreach (SPList objSPList in objSPListCollection)
                    {
                        if (objSPList.BaseType == SPBaseType.DocumentLibrary)
                        {
                            SPListItemCollection objFolders = objSPList.Folders;
                            Console.WriteLine(string.Format("DocumentLibrary={0}, folder count={1}", objSPList.Title, objFolders.Count));
                            foreach (SPListItem item in objFolders)
                            {
                                if (string.IsNullOrEmpty(item.Title))
                                {
                                    item[SPBuiltInFieldId.Title] = item.Name;
                                    item.SystemUpdate(false);
                                }
                            }
                            //break;
                        }
                    }
                    objSPWeb.AllowUnsafeUpdates = false;
                }
            }
        }
    }
}
